package com.shen.pojo;

/**
 * Author:shen
 * CreateDate:2020/5/19.
 * Function:
 */
public class Game {
    public static Level[] levels=new Level[6];//六个级别

    /**
     * 初始化级别信息
     */
    {
        levels[0]=new Level(1,2,2,40,1);
        levels[1]=new Level(2,3,2,26,2);
        levels[2]=new Level(3,4,2,22,5);
        levels[3]=new Level(4,5,2,18,8);
        levels[4]=new Level(5,6,2,15,10);
        levels[5]=new Level(6,7,2,12,15);
    }

    /**
     * 生成随机字符
     * @param strLength
     * @return
     */
    public String printStr(int strLength){
        String str="";
        for (int i=0;i<strLength;i++){
            char c=(char)(Math.random()*(127-33)+33);
            str+=c;
        }
        return str;
    }

    /**
     * 检查是否一致
     */
    public boolean printResult(String randomStr,String userStr,Player player,Level level){
        Long currentTime=System.currentTimeMillis();//获得当前系统的毫秒数
        if(randomStr.equals(userStr.trim())){
            if(((currentTime-player.getStartTime())/1000)>level.timeLimit){
                System.out.println("已超时！！，程序退出！");
                return false;
            }else{
                //积分
                player.setCurrScore(player.getCurrScore()+level.preScore);
                //时间
                player.setElapsedTime((int) ((currentTime-player.getStartTime())/1000));
                return true;
            }
        }else{
            System.out.println("输入不一致！程序退出");
            return false;
        }
    }


    /**
     * 等级类
     */
    public static class Level {
        private int levelNo;//级别号
        private int strLength;//输出的字符串长度
        private int strTime;//输出字符串的次数
        private int timeLimit;//时间限制 秒
        private int preScore;//输入正确的得分

        public Level() {
        }

        public Level(int levelNo, int strLength, int strTime, int timeLimit, int preScore) {
            this.levelNo = levelNo;
            this.strLength = strLength;
            this.strTime = strTime;
            this.timeLimit = timeLimit;
            this.preScore = preScore;
        }

        @Override
        public String toString() {
            return "Level{" +
                    "levelNo=" + levelNo +
                    ", strLength=" + strLength +
                    ", strTime=" + strTime +
                    ", timeLimit=" + timeLimit +
                    ", preScore=" + preScore +
                    '}';
        }

        public int getLevelNo() {
            return levelNo;
        }

        public int getStrLength() {
            return strLength;
        }

        public int getStrTime() {
            return strTime;
        }

        public int getTimeLimit() {
            return timeLimit;
        }

        public int getPreScore() {
            return preScore;
        }
    }

}
